import { createWebHistory, createRouter } from 'vue-router'
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 *
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'RouterName'               // 设定路由的名字, 一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 *
 * meta : {
	noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存 (默认 noCache: false 缓存)
	title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
	icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
	breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
	activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
	// 重定向
	{
		path: '/redirect',
		component: Layout,
		hidden: true,
		children: [
			{
				path: '/redirect/:path(.*)',
				component: () => import('@/views/redirect/index.vue')
			}
		]
	},

	// 登录页
	{
		path: '/login',
		component: () => import('@/views/login'),
		hidden: true
	},

	// 首次登录, 强制修改密码页
	{
		path: '/force-reset-password',
		name: 'forceResetPwd',
		component: () => import('@/views/forceResetPwd.vue'),
		hidden: true
	},
	// 忘记密码
	{
		path: '/forgot-password',
		name: 'forgotPassword',
		component: () => import('@/views/forgotPassword.vue'),
		hidden: true
	},

	// 404
	{
		path: '/:pathMatch(.*)*',
		component: () => import('@/views/error/404'),
		hidden: true
	},

	// 401
	{
		path: '/401',
		component: () => import('@/views/error/401'),
		hidden: true
	},

	// 首页
	{
		path: '',
		component: Layout,
		redirect: '/index',
		children: [
			{
				path: '/index',
				component: () => import('@/views/index'),
				name: 'Index',
				meta: { title: '首页', icon: 'shouye', affix: true, noCache: true }
			}
		]
	},

	// 个人中心
	{
		path: '/user',
		component: Layout,
		hidden: true,
		redirect: 'noredirect',
		children: [
			{
				path: 'profile',
				component: () => import('@/views/system/user/profile/index'),
				name: 'Profile',
				meta: { title: '个人中心', icon: 'user' }
			}
		]
	}
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
	{
		path: '/system/user-auth',
		component: Layout,
		hidden: true,
		permissions: ['system:user:edit'],
		children: [
			{
				path: 'role/:userId(\\d+)',
				component: () => import('@/views/system/user/authRole'),
				name: 'AuthRole',
				meta: { title: '分配角色', activeMenu: '/system/user' }
			}
		]
	},
	{
		path: '/system/role-auth',
		component: Layout,
		hidden: true,
		permissions: ['system:role:edit'],
		children: [
			{
				path: 'user/:roleId(\\d+)',
				component: () => import('@/views/system/role/authUser'),
				name: 'AuthUser',
				meta: { title: '分配用户', activeMenu: '/system/role' }
			}
		]
	},
	{
		path: '/system/dict-data',
		component: Layout,
		hidden: true,
		permissions: ['system:dict:list'],
		children: [
			{
				path: 'index/:dictId(\\d+)',
				component: () => import('@/views/system/dict/data'),
				name: 'Data',
				meta: { title: '字典数据', activeMenu: '/system/dict' }
			}
		]
	},
	{
		path: '/system/oss-config',
		component: Layout,
		hidden: true,
		permissions: ['system:oss:list'],
		children: [
			{
				path: 'index',
				component: () => import('@/views/system/oss/config'),
				name: 'OssConfig',
				meta: { title: '配置管理', activeMenu: '/system/oss' }
			}
		]
	},
	{
		path: '/tool/gen-edit',
		component: Layout,
		hidden: true,
		permissions: ['tool:gen:edit'],
		children: [
			{
				path: 'index/:tableId(\\d+)',
				component: () => import('@/views/tool/gen/editTable'),
				name: 'GenEdit',
				meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
			}
		]
	},

	// Demo
	{
		path: '/logistics',
		component: Layout,
		hidden: false,
		redirect: '/logistics'
	},

	/**
			业务开发添加的动态路由
  */
	// 采购协同
	{
		path: '/purchaseMES',
		component: Layout,
		hidden: false,
		redirect: '/purchaseMES',
		children: [
			/* 物料接收 */
			{
				path: 'materialReceive/toConfirme',
				component: () => import('@/views/orderManage/materialReceive/toConfirme.vue'),
				name: 'toConfirmeProcess',
				meta: { title: '物料接收待确认', icon: 'dot', pageType: 'process', noCache: true }
			},
			{
				path: 'materialReceive/toConfirme_',
				component: () => import('@/views/orderManage/materialReceive/toConfirme.vue'),
				name: 'toConfirmeView',
				meta: { title: '物料查看', icon: 'dot', pageType: 'view', noCache: true }
			},
			{
				path: 'materialReceiveList/toConfirme',
				component: () => import('@/views/orderManage/materialReceiveList/toConfirme.vue'),
				name: 'toListConfirmeProcess',
				meta: { title: '物料接收列表待确认', icon: 'dot', pageType: 'process', noCache: true }
			},
			{
				path: 'materialReceiveList/toConfirme_',
				component: () => import('@/views/orderManage/materialReceiveList/toConfirme.vue'),
				name: 'toListConfirmeView',
				meta: { title: '物料查看', icon: 'dot', pageType: 'view', noCache: true }
			},
			/* 	公告管理 */
			{
				path: 'supplier/add',
				component: () => import('@/views/noticeManage/addEditNotice.vue'),
				name: 'addNotice',
				hidden: true,
				meta: { title: '新增公告' }
			},
			{
				path: 'supplier/detail/:id?',
				component: () => import('@/views/noticeManage/detial.vue'),
				name: 'noticeDetail',
				hidden: true,
				meta: { title: '公告详情' }
			},
			{
				path: 'supplier/edit/:id',
				component: () => import('@/views/noticeManage/addEditNotice.vue'),
				name: 'editNotice',
				hidden: true,
				meta: { title: '编辑公告' }
			},
			{
				path: 'supplier/noticeHistory/detail/:id?',
				component: () => import('@/views/noticeManage/detial.vue'),
				name: 'noticeDetail',
				hidden: true,
				meta: { title: '公告详情' }
			}
		]
	},
	/* 	订单管理 */
	{
		path: '/order',
		component: Layout,
		hidden: true,
		meta: { title: '订单管理', icon: 'dingdan' },
		children: [
			/* 订单接单相关路由 */
			{
				path: 'appointOrder/detail',
				component: () => import('@/views/orderManage/order/appointOrder/appointOrder.vue'),
				name: 'appointOrder',
				hidden: true,
				meta: { title: '标准委外接单', icon: 'dot', pageType: 'process', noCache: true }
			},
			{
				path: 'appointOrder/detail',
				component: () => import('@/views/orderManage/order/appointOrder/appointOrder.vue'),
				name: 'appointOrder_',
				hidden: true,
				meta: { title: '订单接单-标准委外查看', icon: 'dot', pageType: 'view', noCache: true }
			},
			{
				path: 'purchaseDetail',
				component: () => import('@/views/orderManage/order/purchaseDetail.vue'),
				name: 'purchaseHandleprocess',
				hidden: true,
				meta: { title: '标准采购接单', pageType: 'process', noCache: true }
			},
			/* 订单排产相关路由 */
			{
				path: 'appointOrder/detail',
				component: () => import('@/views/orderManage/order/appointOrder/appointOrder.vue'),
				name: 'outsourceScheduling',
				hidden: true,
				meta: { title: '标准委外排产', icon: 'dot', pageType: 'process', noCache: true }
			},
			{
				path: 'appointOrder/detail',
				component: () => import('@/views/orderManage/order/appointOrder/appointOrder.vue'),
				name: 'outsourceScheduling_',
				hidden: true,
				meta: { title: '订单排产-标准委外查看', icon: 'dot', pageType: 'view', noCache: true }
			},
			{
				path: 'outsource/detail/:id',
				component: () => import('@/views/orderManage/order/outsourceDetail.vue'),
				name: 'outsourceDetail',
				hidden: true,
				meta: { title: '标准委外详情' }
			},
			// 从资料修改消息列表跳转
			{
				path: 'outsource/fileChangeDetail_',
				component: () => import('@/views/orderManage/order/fileChangeDetail.vue'),
				name: 'fileChangeDetail',
				hidden: true,
				meta: { title: '资料修改-标准委外详情' }
			},
			{
				path: 'purchaseDetail_',
				component: () => import('@/views/orderManage/order/purchaseDetail.vue'),
				name: 'purchaseHandleView',
				hidden: true,
				meta: { title: '标准采购详情', pageType: 'view', noCache: true }
			},
			{
				path: 'detail/:id?',
				component: () => import('@/views/problem/problemDetail.vue'),
				hidden: true,
				name: 'widthOfClothDetail',
				meta: { title: '幅宽缩率详情' }
			},
			{
				path: 'handler/:id?',
				component: () => import('@/views/problem/problemDetail.vue'),
				hidden: true,
				name: 'handleWidthOfCloth',
				meta: { title: '跟进幅宽缩率' }
			},
			{
				path: 'addWidthOfCloth',
				component: () => import('@/views/orderManage/widthOfCloth/addWidthOfCloth.vue'),
				hidden: true,
				name: 'addWidthOfCloth',
				meta: { title: '新增幅宽缩率', noCache: true }
			},
			{
				path: 'materialList',
				component: () => import('@/views/orderManage/style/materialList.vue'),
				name: 'materialList',
				meta: { title: '用料清单', icon: 'dot', noCache: true }
			}
		]
	},
	// 生产管理
	{
		// 检验订单
		path: '/produce',
		component: Layout,
		hidden: true,
		meta: { title: '生产管理', icon: 'fahuo' },
		children: [
			// 检验订单
			{
				path: 'receiveInspection/reportDetail/:id',
				component: () => import('@/views/inspectionInfo/components/report.vue'),
				name: 'reportDetail',
				hidden: true,
				meta: { title: '查看报告' }
			}
		]
	},
	// 质量管理
	{
		path: '/quality',
		component: Layout,
		hidden: false,
		redirect: '/quality',
		children: [
			// 检品信息
			{
				path: 'inspectionInfo/receiveOrderDetail',
				component: () => import('@/views/inspectionInfo/receiveOrder/detail.vue'),
				name: 'receiveOrderDetail',
				meta: { title: '检品接单详情' }
			},
			// 生成全检检品报告书
			{
				path: 'inspectionInfo/report/:id',
				component: () => import('@/views/inspectionInfo/report/index.vue'),
				name: 'report',
				hidden: true,
				meta: { title: '全检检品报告书' }
			},
			// 查看全检检品报告书
			{
				path: 'inspectionInfo/reportDetail/:id',
				component: () => import('@/views/inspectionInfo/components/report.vue'),
				name: 'reportDetail_',
				hidden: true,
				meta: { title: '查看报告' }
			}
		]
	},
	// 物流管理
	{
		path: '/logistics',
		component: Layout,
		hidden: true,
		meta: { title: '物流管理', icon: 'fahuo' },
		children: [
			{
				path: 'order',
				component: () => import('@/views/logistics/order.vue'),
				name: 'order',
				meta: { title: '订单管理', icon: 'dot' }
			},
			{
				path: 'Statistics/FreightByDepartment',
				component: () => import('@/views/logistics/Statistics/FreightByDepartment.vue'),
				name: 'FreightByDepartment',
				meta: { title: '部门物流费用占比分析', icon: 'dot' }
			},
			{
				path: 'Statistics/CostByCourierCompany',
				component: () => import('@/views/logistics/Statistics/CostByCourierCompany.vue'),
				name: 'CostByCourierCompany',
				meta: { title: '快递公司物流费用占比分析', icon: 'dot' }
			},
			{
				path: 'Statistics/CompanyExpressCostStatistics',
				component: () => import('@/views/logistics/Statistics/CompanyExpressCostStatistics.vue'),
				name: 'CompanyExpressCostStatistics',
				meta: { title: '整体物流费用占比分析', icon: 'dot' }
			}
		]
	},
	/* 财务管理 */
	{
		path: '/finance',
		component: Layout,
		hidden: false,
		meta: { title: '财务管理' },
		/* 	对账管理 */
		children: [
			{
				path: 'billManage/process',
				component: () => import('@/views/billManage/compareBills/detail.vue'),
				name: 'billProcess',
				meta: { title: '单据对账应付单', icon: 'dot', pageType: 'process' }
			},
			{
				path: 'billManage/detail',
				component: () => import('@/views/billManage/compareBills/detail.vue'),
				name: 'billDetail',
				meta: { title: '单据对账应付单已确认', icon: 'dot', pageType: 'detail' }
			}
		]
	},
	// 运营管理
	{
		path: '/operation',
		component: Layout,
		hidden: false,
		redirect: '/operation',
		children: [
			/* 	问题反馈 */
			{
				path: 'problemList/detail/:id?',
				component: () => import('@/views/problem/problemDetail.vue'),
				hidden: true,
				name: 'problemDetail',
				meta: { title: '问题反馈详情' }
			},
			{
				path: 'problemList/add',
				component: () => import('@/views/problem/addProblem.vue'),
				hidden: true,
				name: 'addProblem',
				meta: { title: '新增问题反馈', noCache: true }
			},
			{
				path: 'problemList/handler/:id?',
				component: () => import('@/views/problem/problemDetail.vue'),
				hidden: true,
				name: 'handlerProblem',
				meta: { title: '跟进问题反馈' }
			}
		]
	},
	/* 	物料直发 */
	{
		path: '/material',
		component: Layout,
		hidden: true,
		meta: { title: '物料直发', icon: 'duizhang' },
		children: [
			{
				path: 'materDelivery',
				component: () => import('@/views/material/materDelivery/index.vue'),
				name: 'materDelivery',
				meta: { title: '物料直发', icon: 'dot' }
			},
			{
				path: 'materDeliveryDetail',
				component: () => import('@/views/material/materDelivery/detail.vue'),
				name: 'materDeliveryDetail',
				meta: { title: '物料直发详情', icon: 'dot' }
			},
			{
				path: 'materExamine',
				component: () => import('@/views/material/materExamine/index.vue'),
				name: 'materExamine',
				meta: { title: '物料直发审核', icon: 'dot' }
			},
			{
				path: 'materExamineDetail',
				component: () => import('@/views/material/materExamine/detail.vue'),
				name: 'materExamineDetail',
				meta: { title: '物料直发审核详情', icon: 'dot' }
			},
			{
				path: 'materIncome',
				component: () => import('@/views/material/materIncome/index.vue'),
				name: 'materIncome',
				meta: { title: '物料列表', icon: 'dot' }
			},
			{
				path: 'materIncomeDetail',
				component: () => import('@/views/material/materIncome/detail.vue'),
				name: 'materIncomeDetail',
				meta: { title: '物料列表详情', icon: 'dot' }
			},
			{
				path: 'materHandle',
				component: () => import('@/views/material/materHandle/index.vue'),
				name: 'materHandle',
				meta: { title: '物料待处理', icon: 'dot' }
			},
			{
				path: 'materHandleDetail',
				component: () => import('@/views/material/materHandle/detail.vue'),
				name: 'materHandleDetail',
				meta: { title: '物料待处理详情', icon: 'dot' }
			},
			{
				path: 'materForms',
				component: () => import('@/views/material/materForms/index.vue'),
				name: 'materForms',
				meta: { title: '直发报表', icon: 'dot' }
			},
			{
				path: 'receiMater',
				component: () => import('@/views/material/receiMater/index.vue'),
				name: 'receiMater',
				meta: { title: '物料收料', icon: 'dot' }
			},
			{
				path: 'receiMaterDetail',
				component: () => import('@/views/material/receiMater/detail.vue'),
				name: 'receiMaterDetail',
				meta: { title: '物料收料详情', icon: 'dot' }
			}
		]
	}
]

const router = createRouter({
	history: createWebHistory(import.meta.env.VITE_APP_CONTEXT_PATH),
	routes: constantRoutes,
	scrollBehavior(to, from, savedPosition) {
		if (savedPosition) {
			return savedPosition
		} else {
			return { top: 0 }
		}
	}
})

export default router
